****
* Arbitrage
***

clear 
	
	
 	
 	
	
	*set gridding style for graphs
			grstyle init

			grstyle set plain, horizontal   dotted
			
			
			
	*** load relevant data


		
		use "$Replicationdirectory/_Work/TEMP/_data_bonds"	
		
				
			
			
			
			***** correlations


 
				 



				
					*** between selective default risk and baseline default risk
					
					pwcorr  ytm_paris ytm_london if default==1, star(0.01)
					
 					
					eststo clear
		
					
					foreach x of global markets{
  					 eststo corr_`x'_predefault: reg    ytm_`x' ytm_london if default==0  , robust beta
  					 eststo corr_`x'_default: reg    ytm_`x' ytm_london if default==1  , robust beta
						}
					 
					 
					capture mkdir "$Replicationdirectory/_Work/Output/TABS/TAB_1"
					  
					
					esttab corr_paris_predefault corr_amsterdam_predefault corr_zurich_predefault using "$Replicationdirectory/_Work/Output/TABS/TAB_1/TAB1_A1_CORR_YIELD_PRE.tex"   , beta replace b(2) se(2)
 
					esttab corr_paris_default corr_amsterdam_default corr_zurich_default using "$Replicationdirectory/_Work/Output/TABS/TAB_1/TAB1_A2_CORR_YIELD_POST.tex"   , beta replace b(2) se(2)
					
					
				 
				 


		
		 
					
					
***** IRFs 		
	
 				
 			 
						
						 
				* prelims  for IRF code
				tsset date, daily
				sort date
				
				
				local lag=4

						
					gen time =_n 
					tsset time
					sort time
					rename date daten
					
						 foreach market in paris london    {
						   							gen dytm_`market'_lastavail=d.ytm_`market'_lastavail
									}
			
		 

 						
*** pre default ***
	
	
	preserve 
					 
					 keep if default==0
					
					tsset daten
 					   
					tsset time, daily
					
							
				* Choose impulse response horizon
				local hmax = 5

				/* Generate LHS variables for the LPs */

				* levels
				forvalues h = 0/`hmax' {
					gen ytm_paris_lastavail_`h' = f`h'.ytm_paris_lastavail 
				}

				* differences
				forvalues h = 0/`hmax' {
					gen ytm_paris_lastavaild`h' = f`h'.ytm_paris_lastavail - l.f`h'.ytm_paris_lastavail 
				}

				* Cumulative
				forvalues h = 0/`hmax' {
					gen ytm_paris_lastavailc`h' = f`h'.ytm_paris_lastavail - l.ytm_paris_lastavail 
				}

				 
				/* Run the LPs */
				* Levels
				eststo clear
				cap drop b u d Days Zero
				gen Days = _n-1 if _n<=`hmax'
				gen Zero =  0    if _n<=`hmax'
				gen b=0
				gen u=0
				gen d=0
				forv h = 0/`hmax' {
					* levels
					 reg ytm_paris_lastavail_`h' l(0/`lag').ytm_london_lastavail l(1/`lag').ytm_paris_lastavail, vce(robust)
				replace b = _b[ytm_london_lastavail]                    if _n == `h'+1
				replace u = _b[ytm_london_lastavail] + 2.575* _se[ytm_london_lastavail]  if _n == `h'+1
				replace d = _b[ytm_london_lastavail] - 2.575* _se[ytm_london_lastavail]  if _n == `h'+1
				eststo
				}
				* nois esttab , se nocons keep(ytm_london_lastavail)
				gen b_level = b

				* Differences
				eststo clear
				cap drop b u d Days Zero
				gen Days = _n-1 if _n<=`hmax'
				gen Zero =  0    if _n<=`hmax'
				gen b=0
				gen u=0
				gen d=0
				forv h = 0/`hmax' {
					 reg ytm_paris_lastavaild`h' l(0/`lag').dytm_london_lastavail l(1/`lag').dytm_paris_lastavail, vce(robust)
				replace b = _b[dytm_london_lastavail]                     if _n == `h'+1
				replace u = _b[dytm_london_lastavail] + 2.575* _se[dytm_london_lastavail]  if _n == `h'+1
				replace d = _b[dytm_london_lastavail] - 2.575* _se[dytm_london_lastavail]  if _n == `h'+1
				eststo
				}
				* nois esttab , se nocons keep(dytm_london_lastavail)
				
						
						/*
						twoway ///
						(rarea u d  Days,  ///
						fcolor(gs13) lcolor(gs13) lw(none) lpattern(solid)) ///
						(line b Days, lcolor(blue) ///
						lpattern(solid) lwidth(thick)) ///
						(line Zero Days, lcolor(black)), legend(off) ///
						title("Impulse response of ytm_paris_lastavail to 1pp shock to ytm_london_lastavail", color(black) size(medsmall)) ///
						ytitle("Percent", size(medsmall)) xtitle("Days", size(medsmall)) ///
						graphregion(color(white)) plotregion(color(white))

						gr rename fig_diff, replace
						*/
						
						
					 
						twoway ///
						(rarea u d  Days,  ///
						fcolor(gs13) lcolor(gs13) lw(none) lpattern(solid)) ///
						(line b Days, lcolor(blue) ///
						lpattern(solid) lwidth(thick) legend(off)) ///
						(line Zero Days, lcolor(black)), title("{stMono:Dawes} ",size(mediumsmal) color(black)) legend(off) ///
						graphregion(color(white)) plotregion(color(white)) ///
						ysc(r(-0.3 0.8)) ylabel(-0.2(0.2)0.8, angle(0) grid) xtitle("")
						
						* ytitle("Percent", size(medsmall)) xtitle("Days", size(medsmall)) ///

 						 
						
						graph export "$Replicationdirectory/_Work/TEMP/DAWES_Paris_London_PREDEFAULT_DIF.pdf", replace  as(pdf)
	 
						graph save "$Replicationdirectory/_Work/TEMP/DAWES_Paris_London_PREDEFAULT_DIF", replace 
	
 			 
				 

									
								 
								 
								 
									
															
										 
									
									
	 restore 				
					

					
*** post default ***
			
					 
					 keep if default==1
					
					tsset daten
					*keep if tin(1Jan1935,31Mar1935)
					   
					tsset time, daily
					
							
				* Choose impulse response horizon
				local hmax = 5

				/* Generate LHS variables for the LPs */

				* levels
				forvalues h = 0/`hmax' {
					gen ytm_paris_lastavail_`h' = f`h'.ytm_paris_lastavail 
				}

				* differences
				forvalues h = 0/`hmax' {
					gen ytm_paris_lastavaild`h' = f`h'.ytm_paris_lastavail - l.f`h'.ytm_paris_lastavail 
				}

				* Cumulative
				forvalues h = 0/`hmax' {
					gen ytm_paris_lastavailc`h' = f`h'.ytm_paris_lastavail - l.ytm_paris_lastavail 
				}

				 
				/* Run the LPs */
				* Levels
				eststo clear
				cap drop b u d Days Zero
				gen Days = _n-1 if _n<=`hmax'
				gen Zero =  0    if _n<=`hmax'
				gen b=0
				gen u=0
				gen d=0
				forv h = 0/`hmax' {
					* levels
					 reg ytm_paris_lastavail_`h' l(0/`lag').ytm_london_lastavail l(1/`lag').ytm_paris_lastavail, vce(robust)
				replace b = _b[ytm_london_lastavail]                    if _n == `h'+1
				replace u = _b[ytm_london_lastavail] + 2.575* _se[ytm_london_lastavail]  if _n == `h'+1
				replace d = _b[ytm_london_lastavail] - 2.575* _se[ytm_london_lastavail]  if _n == `h'+1
				eststo
				}
				* nois esttab , se nocons keep(ytm_london_lastavail)
				gen b_level = b

				* Differences
				eststo clear
				cap drop b u d Days Zero
				gen Days = _n-1 if _n<=`hmax'
				gen Zero =  0    if _n<=`hmax'
				gen b=0
				gen u=0
				gen d=0
				forv h = 0/`hmax' {
					 reg ytm_paris_lastavaild`h' l(0/`lag').dytm_london_lastavail l(1/`lag').dytm_paris_lastavail, vce(robust)
				replace b = _b[dytm_london_lastavail]                     if _n == `h'+1
				replace u = _b[dytm_london_lastavail] + 2.575* _se[dytm_london_lastavail]  if _n == `h'+1
				replace d = _b[dytm_london_lastavail] - 2.575* _se[dytm_london_lastavail]  if _n == `h'+1
				eststo
				}
				* nois esttab , se nocons keep(dytm_london_lastavail)
				 
					twoway ///
						(rarea u d  Days,  ///
						fcolor(gs13) lcolor(gs13) lw(none) lpattern(solid)) ///
						(line b Days, lcolor(blue) ///
						lpattern(solid) lwidth(thick)) ///
						(line Zero Days, lcolor(black)), title("{stMono:Dawes} ",size(mediumsmal) color(black)) legend(off) ///
						graphregion(color(white)) plotregion(color(white)) ///
						ysc(r(-0.3 0.8)) ylabel(-0.2(0.2)0.8, angle(0) grid) xtitle("")
						
						* ytitle("Percent", size(medsmall)) xtitle("Days", size(medsmall)) ///

 						
						
						graph export "$Replicationdirectory/_Work/TEMP/DAWES_Paris_London_POSTDEFAULT_DIF.pdf", replace 
	
						graph save "$Replicationdirectory/_Work/TEMP/DAWES_Paris_London_POSTDEFAULT_DIF", replace 

				
			 	 

									
								 
								 
								 
									
									 
